package com.kaibes.web.encryption;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.springframework.context.annotation.Configuration;

@Configuration
@WebListener
public class EncryptionSessionListener implements HttpSessionListener {

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        RsaKey rsaKey = EncryptionUtils.createRsaKey();
        se.getSession().setAttribute(EncryptionRes.RSA_PRIVATE_KEY, rsaKey.getPrivateKey());
        se.getSession().setAttribute(EncryptionRes.RSA_PUBLIC_KEY, rsaKey.getPublicKey());
    }
    
    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
    }
}
